3 572 - Oil deposits (UVa Online Judge)
4 1959 - Oil deposits (TJU Online Judge)
6 Author: Andrés Mejía-Posada (http://github.com/andmej/acm)
7 Algorithm: Depth-first search
13 int di
[] = {-1, -1, -1, +0, +1, +1, +1, +0};
14 int dj
[] = {-1, +0, +1, +1, +1, +0, -1, -1};
21 void dfs(const int &i
, const int &j
){
22 if ( (0 <= i
&& i
< r
&& 0 <= j
&& j
< c
) == false){
25 if (v
[i
][j
] || g
[i
][j
] == '*') return;
29 for (int k
=0; k
<8; ++k
){
30 dfs(i
+ di
[k
], j
+ dj
[k
]);
36 while (cin
>> r
>> c
&& (r
+c
)){
37 for (int i
=0; i
<r
; ++i
){
38 for (int j
=0; j
<c
; ++j
){
45 for (int i
=0; i
<r
; ++i
){
46 for (int j
=0; j
<c
; ++j
){
47 if (!v
[i
][j
] && g
[i
][j
] == '@'){